*************************************************************************
*																		*
*					Campaign Panel Book Chapter 6 - Communication variables				*
*																		*
*************************************************************************	

use "${data}\ZA5305_en_v5-0-0.dta", clear

/*  
 Basic reasoning
 Replacement for points in time before an event took place:
•	If purely the measurement of reception is of interest, a 0 is imputed
•	If the evaluation of the event is measured, a neutral evaluation (0.5) is
	imputed. If the event was not observed, the respondent also receives the 
	neutral value for the evaluation

Replacement for points in time after an event took place:
•	If purely the measurement of reception is of interest and the information whether
	the event has taken place, data is collected only in the wave following the 
	event and for all following waves this reception measure (0 or 1) is imputed
•	If the evaluation of the event is supposed to be measured and this evaluation
	is only asked for in one wave (the one directly following the event), the 
	measurement from this wave is imputed in all following waves
*/





********************************************************************************
**
** TV-debate (Own evaluation)
**
********************************************************************************

// Neutral values

foreach welle of numlist 1/5 {
   foreach partei of numlist 1 4 {
      gen tvduell`partei'`welle' = 3
   }
}

recode kp6_1810 (1=5) (2=4) (4=2) (5=1) (3=3) (99 100=.), gen(tvd1)
recode kp6_1820 (1=5) (2=4) (4=2) (5=1) (3=3) (99 100=.), gen(tvd4)

foreach welle of numlist 6/7 {
   foreach partei of numlist 1 4 {
      gen tvduell`partei'`welle' = tvd`partei'
      replace tvduell`partei'`welle' = 3 if kp6_1800==3
   }
}

foreach welle of numlist 1/7 {
	foreach partei of numlist 1 4 {
	replace tvduell`partei'`welle'=(tvduell`partei'`welle'-1)/4
	}
}

sum tvduell??

drop tvd?

********************************************************************************
**
** TV-debate (social environment)
**
********************************************************************************

// Neutral values
foreach welle of numlist 1/5 {
   foreach partei of numlist 1 4 {
      gen tvduell_su`partei'`welle' = 3
   }
}

recode kp6_1910 (1=5) (2=4) (4=2) (5=1) (3=3) (99 100=.), gen(tvd_su1)
recode kp6_1920 (1=5) (2=4) (4=2) (5=1) (3=3) (99 100=.), gen(tvd_su4)

foreach welle of numlist 6/7 {
   foreach partei of numlist 1 4 {
      gen tvduell_su`partei'`welle' = tvd_su`partei'
      replace tvduell_su`partei'`welle' = 3 if kp6_1900==3
   }
}

foreach welle of numlist 1/7 {
	foreach partei of numlist 1 4 {
	replace tvduell_su`partei'`welle'=(tvduell_su`partei'`welle'-1)/4
	}
}

sum tvduell_su??

********************************************************************************
**
** TV-debate(Media)
**
********************************************************************************

// Neutral values
foreach welle of numlist 1/5 {
   foreach partei of numlist 1 4 {
      gen tvduell_md`partei'`welle' = 3
   }
}

recode kp6_1880 (1=5) (2=4) (4=2) (5=1) (3=3) (99 100=.), gen(tvd_md1)
recode kp6_1890 (1=5) (2=4) (4=2) (5=1) (3=3) (99 100=.), gen(tvd_md4)

foreach welle of numlist 6/7 {
   foreach partei of numlist 1 4 {
      gen tvduell_md`partei'`welle' = tvd_md`partei'
      replace tvduell_md`partei'`welle' = 3 if kp6_1870==3
   }
}

foreach welle of numlist 1/7 {
	foreach partei of numlist 1 4 {
	replace tvduell_md`partei'`welle'=(tvduell_md`partei'`welle'-1)/4
	}
}

sum tvduell_md??


********************************************************************************
**
** Talks about politics
**
********************************************************************************



foreach welle of numlist 1/7 {
   foreach partei of numlist 1 4/7 {
      gen gespr`partei'`welle' = kp`welle'_1970==`partei'
	  replace gespr`partei'`welle' = . if kp`welle'_1970==99
   }
}

tab gespr43



********************************************************************************
**Party contacts: campaign events

********************************************************************************

// Neutral values

foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_kundgeb`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_kundgeb1`welle'= kp`welle'_420a_1==1
   replace pk_kundgeb4`welle'= kp`welle'_420a_2==1 
   replace pk_kundgeb5`welle'= kp`welle'_420a_3==1 
   replace pk_kundgeb6`welle'= kp`welle'_420a_4==1 
   replace pk_kundgeb7`welle'= kp`welle'_420a_5==1 
}



********************************************************************************
**Party contacts: post
**
********************************************************************************

// Neutral values
foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_post`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_post1`welle'= kp`welle'_420c_1==1
   replace pk_post4`welle'= kp`welle'_420c_2==1 
   replace pk_post5`welle'= kp`welle'_420c_3==1 
   replace pk_post6`welle'= kp`welle'_420c_4==1 
   replace pk_post7`welle'= kp`welle'_420c_5==1 
}

********************************************************************************
** Party contacts: email/sms
**
********************************************************************************

// Neutral values
foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_email`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_email1`welle'= kp`welle'_420b_1==1
   replace pk_email4`welle'= kp`welle'_420b_2==1 
   replace pk_email5`welle'= kp`welle'_420b_3==1 
   replace pk_email6`welle'= kp`welle'_420b_4==1 
   replace pk_email7`welle'= kp`welle'_420b_5==1 
}


********************************************************************************
**
** Party contacts: TV spots
**
********************************************************************************

// Neutral values
foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_tvspot`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_tvspot1`welle'= kp`welle'_420d_1==1
   replace pk_tvspot4`welle'= kp`welle'_420d_2==1 
   replace pk_tvspot5`welle'= kp`welle'_420d_3==1 
   replace pk_tvspot6`welle'= kp`welle'_420d_4==1 
   replace pk_tvspot7`welle'= kp`welle'_420d_5==1 
}


********************************************************************************
**
** Party contacts: radio
**
********************************************************************************

// Neutral values
foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_radio`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_radio1`welle'= kp`welle'_420e_1==1
   replace pk_radio4`welle'= kp`welle'_420e_2==1 
   replace pk_radio5`welle'= kp`welle'_420e_3==1 
   replace pk_radio6`welle'= kp`welle'_420e_4==1 
   replace pk_radio7`welle'= kp`welle'_420e_5==1 
}


********************************************************************************
**
** Party contacts: Ads in newspapers/magazines
**
********************************************************************************

// Neutral values
foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_anzeige`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_anzeige1`welle'= kp`welle'_420f_1==1
   replace pk_anzeige4`welle'= kp`welle'_420f_2==1 
   replace pk_anzeige5`welle'= kp`welle'_420f_3==1 
   replace pk_anzeige6`welle'= kp`welle'_420f_4==1 
   replace pk_anzeige7`welle'= kp`welle'_420f_5==1 
}


********************************************************************************
**
** Party contacts: election poster
**
********************************************************************************

// Neutral values
foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_plakat`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_plakat1`welle'= kp`welle'_420g_1==1
   replace pk_plakat4`welle'= kp`welle'_420g_2==1 
   replace pk_plakat5`welle'= kp`welle'_420g_3==1 
   replace pk_plakat6`welle'= kp`welle'_420g_4==1 
   replace pk_plakat7`welle'= kp`welle'_420g_5==1 
}

********************************************************************************
**
** Party contacts: campaign booth
**
********************************************************************************

// Neutral values
foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_stand`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_stand1`welle'= kp`welle'_420h_1==1
   replace pk_stand4`welle'= kp`welle'_420h_2==1 
   replace pk_stand5`welle'= kp`welle'_420h_3==1 
   replace pk_stand6`welle'= kp`welle'_420h_4==1 
   replace pk_stand7`welle'= kp`welle'_420h_5==1 
}


********************************************************************************
**
** Party contacts: Canvassing
**
********************************************************************************

// Neutral values
foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_canvass`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_canvass1`welle'= kp`welle'_420i_1==1
   replace pk_canvass4`welle'= kp`welle'_420i_2==1 
   replace pk_canvass5`welle'= kp`welle'_420i_3==1 
   replace pk_canvass6`welle'= kp`welle'_420i_4==1 
   replace pk_canvass7`welle'= kp`welle'_420i_5==1 
}

********************************************************************************
**
** Party contacts: telefone ads
**
********************************************************************************

// Neutral values
foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_tel`partei'`welle' = 0
}
}

foreach welle of numlist 2/5 7 {
   replace pk_tel1`welle'= kp`welle'_420j_1==1
   replace pk_tel4`welle'= kp`welle'_420j_2==1 
   replace pk_tel5`welle'= kp`welle'_420j_3==1 
   replace pk_tel6`welle'= kp`welle'_420j_4==1 
   replace pk_tel7`welle'= kp`welle'_420j_5==1 
}



********************************************************************************
**
** Party contacts: website
**
********************************************************************************

// Neutral values
foreach welle of numlist 1/7 {
foreach partei of numlist 1 4/7 {
   gen pk_website`partei'`welle' = 0
}
}

foreach welle of numlist 2/7 {
   replace pk_website1`welle'= kp`welle'_420k_1==1
   replace pk_website4`welle'= kp`welle'_420k_2==1 
   replace pk_website5`welle'= kp`welle'_420k_3==1 
   replace pk_website6`welle'= kp`welle'_420k_4==1 
   replace pk_website7`welle'= kp`welle'_420k_5==1 
}



* Indexes for campaign contact with individual parties

foreach welle of numlist 2/6 {
foreach party of numlist 1 4/7 {
egen pk_gesamti`party'`welle' = anycount(pk_kundgeb`party'`welle' ///
	pk_tvspot`party'`welle' pk_radio`party'`welle' pk_plakat`party'`welle'  ///
	 pk_stand`party'`welle' pk_website`party'`welle'), ///
	values(1)
replace pk_gesamti`party'`welle' = pk_gesamti`party'`welle'+1 /// hier wieder Flumail
    if pk_post`party'`welle'==1 | pk_email`party'`welle'==1

replace pk_gesamti`party'`welle' = . if kp`welle'_400==99 | kp`welle'_400==. 
gen pk_gesamtin`party'`welle' = pk_gesamti`party'`welle'/7
}
}


list pk_kundgeb46 pk_tvspot46 pk_radio46 ///
		pk_plakat46 pk_stand46 ///
		pk_website46 pk_post46 ///
		pk_email46 kp6_400 pk_gesamtin46
		
list kp6_420?_1 pk_gesamtin16

* W1: Assumption constant to W2
foreach party of numlist 1 4/7 {
gen pk_gesamtin`party'1 = pk_gesamtin`party'2
}


* W7 different question wording, therefore imputation from 6

foreach party of numlist 1 4/7 {
gen pk_gesamtin`party'7 = pk_gesamtin`party'6
}
sum pk_gesamtin*


drop pk_gesamti??
drop pk_kundgeb?? ///
	pk_post?? pk_email??  ///
	pk_tvspot?? pk_radio?? ///
	pk_anzeige?? pk_plakat?? ///
	pk_stand?? pk_canvass?? pk_tel?? ///
	pk_website??

keep lfdn tvduell11-pk_gesamtin77
drop tvd_su? tvd_md?

save "${path}\Reproducible Do-Files\Chapter 6\Data\komm_variablen09.dta", replace

